home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / CHIP 2005-06.iso / program / yazilim / myscreencapture.exe / {app} / Demo VB6 / cDIBSectionmod.cls next >
Encoding:
Visual Basic class definition  |  2004-10-13  |  6.0 KB  |  177 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cDIBSection"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. '
  16. 'This is an example showing how to save a picture into JPEG format
  17. 'using the INTEL FREE Library.
  18. 'There is NO SUPPORT on this part of code.
  19. '
  20. 'If you don't need to save in JPEG format the capture, you don't need to
  21. 'include this part of code in your application.
  22. '
  23.  
  24. ' ==================================================================================
  25. ' Requires:    mIJLmod.cls
  26. '              ijl15.dll (Intel)
  27. ' ==================================================================================
  28.  
  29. Private Type RGBQUAD
  30.     rgbBlue As Byte
  31.     rgbGreen As Byte
  32.     rgbRed As Byte
  33.     rgbReserved As Byte
  34. End Type
  35. Private Type BITMAPINFOHEADER '40 bytes
  36.     biSize As Long
  37.     biWidth As Long
  38.     biHeight As Long
  39.     biPlanes As Integer
  40.     biBitCount As Integer
  41.     biCompression As Long
  42.     biSizeImage As Long
  43.     biXPelsPerMeter As Long
  44.     biYPelsPerMeter As Long
  45.     biClrUsed As Long
  46.     biClrImportant As Long
  47. End Type
  48. Private Type BITMAPINFO
  49.     bmiHeader As BITMAPINFOHEADER
  50.     bmiColors As RGBQUAD
  51. End Type
  52. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
  53. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  54.  
  55. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  56. Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, pBitmapInfo As BITMAPINFO, ByVal un As _
  57.     Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
  58. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth _
  59.     As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As _
  60.     Long) As Long
  61. Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
  62. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  63. Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
  64. Private Const BI_RGB = 0&
  65. Private Const BI_RLE4 = 2&
  66. Private Const BI_RLE8 = 1&
  67. Private Const DIB_RGB_COLORS = 0 '  color table in RGBs
  68. Private Type BITMAP
  69.     bmType As Long
  70.     bmWidth As Long
  71.     bmHeight As Long
  72.     bmWidthBytes As Long
  73.     bmPlanes As Integer
  74.     bmBitsPixel As Integer
  75.     bmBits As Long
  76. End Type
  77. Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, _
  78.     lpObject As Any) As Long
  79.  
  80. ' Handle to the current DIBSection:
  81. Private m_hDIb As Long
  82. ' Handle to the old bitmap in the DC, for clear up:
  83. Private m_hBmpOld As Long
  84. ' Handle to the Device context holding the DIBSection:
  85. Private m_hDC As Long
  86. ' Address of memory pointing to the DIBSection's bits:
  87. Private m_lPtr As Long
  88. ' Type containing the Bitmap information:
  89. Private m_tBI As BITMAPINFO
  90.  
  91. Public Property Get BytesPerScanLine() As Long
  92.     ' Scans must align on dword boundaries:
  93.     BytesPerScanLine = (m_tBI.bmiHeader.biWidth * 3 + 3) And &HFFFFFFFC
  94. End Property
  95.  
  96. Public Property Get Width() As Long
  97.     Width = m_tBI.bmiHeader.biWidth
  98. End Property
  99.  
  100. Public Property Get Height() As Long
  101.     Height = m_tBI.bmiHeader.biHeight
  102. End Property
  103.  
  104. Public Sub LoadPictureBlt(ByVal lhDC As Long, Optional ByVal lSrcLeft As Long = 0, Optional ByVal lSrcTop _
  105.         As Long = 0, Optional ByVal lSrcWidth As Long = -1, Optional ByVal lSrcHeight As Long = -1, Optional ByVal _
  106.         eRop As RasterOpConstants = vbSrcCopy)
  107.     If lSrcWidth < 0 Then lSrcWidth = m_tBI.bmiHeader.biWidth
  108.     If lSrcHeight < 0 Then lSrcHeight = m_tBI.bmiHeader.biHeight
  109.     BitBlt m_hDC, 0, 0, lSrcWidth, lSrcHeight, lhDC, lSrcLeft, lSrcTop, eRop
  110. End Sub
  111.  
  112. Public Property Get DIBSectionBitsPtr() As Long
  113.     DIBSectionBitsPtr = m_lPtr
  114. End Property
  115.  
  116. Public Sub ClearUp()
  117.     If (m_hDC <> 0) Then
  118.         If (m_hDIb <> 0) Then
  119.             SelectObject m_hDC, m_hBmpOld
  120.             DeleteObject m_hDIb
  121.         End If
  122.         DeleteObject m_hDC
  123.     End If
  124.     m_hDC = 0: m_hDIb = 0: m_hBmpOld = 0: m_lPtr = 0
  125. End Sub
  126.  
  127. Public Function CreateFromPicture(ByRef picThis As StdPicture)
  128.   Dim lhDC As Long
  129.   Dim lhDCDesktop As Long
  130.   Dim lhBmpOld As Long
  131.   Dim tBMP As BITMAP
  132.     
  133.     GetObjectAPI picThis.handle, Len(tBMP), tBMP
  134.     If (Create(tBMP.bmWidth, tBMP.bmHeight)) Then
  135.         lhDCDesktop = GetDC(GetDesktopWindow())
  136.         If (lhDCDesktop <> 0) Then
  137.             lhDC = CreateCompatibleDC(lhDCDesktop)
  138.             DeleteDC lhDCDesktop
  139.             If (lhDC <> 0) Then
  140.                 lhBmpOld = SelectObject(lhDC, picThis.handle)
  141.                 LoadPictureBlt lhDC
  142.                 SelectObject lhDC, lhBmpOld
  143.                 DeleteObject lhDC
  144.             End If
  145.         End If
  146.     End If
  147. End Function
  148.  
  149. Public Function CreateDIB(ByVal lhDC As Long, ByVal lWidth As Long, ByVal lHeight As Long, ByRef hDib As Long _
  150.         ) As Boolean
  151.     With m_tBI.bmiHeader
  152.         .biSize = Len(m_tBI.bmiHeader)
  153.         .biWidth = lWidth
  154.         .biHeight = lHeight
  155.         .biPlanes = 1
  156.         .biBitCount = 24
  157.         .biCompression = BI_RGB
  158.         .biSizeImage = BytesPerScanLine * .biHeight
  159.     End With
  160.     hDib = CreateDIBSection(lhDC, m_tBI, DIB_RGB_COLORS, m_lPtr, 0, 0)
  161.     CreateDIB = (hDib <> 0)
  162. End Function
  163.  
  164. Public Function Create(ByVal lWidth As Long, ByVal lHeight As Long) As Boolean
  165.     ClearUp
  166.     m_hDC = CreateCompatibleDC(0)
  167.     If (m_hDC <> 0) Then
  168.         If (CreateDIB(m_hDC, lWidth, lHeight, m_hDIb)) Then
  169.             m_hBmpOld = SelectObject(m_hDC, m_hDIb)
  170.             Create = True
  171.         Else
  172.             DeleteObject m_hDC
  173.             m_hDC = 0
  174.         End If
  175.     End If
  176. End Function
  177.